<?php

namespace App\Http\Controllers\Traits;

trait DestroyResource
{
    /**
     * Resource Controller for Destrot method
     *
     * @param Request $request
     *
     * @return \Dingo\Api\Http\Response|void
     */
    public function destroy()
    {
        $model = $this->getResourceFromRoute();

        $this->try('deleting', $model);

        $model->delete();

        return $this->response->noContent();
    }

    /**
     * Delete multiple resources
     *
     * @return mixed
     */
    public function multipleDestroy()
    {
        $models = request('models', []);

        $this->model
            ->whereIn('id', $models)
            ->get()
            ->each(function ($model) {
                $this->try('deleting', $model);
                $model->delete();
            });

        return $this->response->noContent();
    }
}
